package com.financing.platform.service.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.financing.platform.dao.IOrderPhoDao;
import com.financing.platform.dto.OrderTmpDTO;
import com.financing.platform.service.IOrderPhoService;
import com.financing.platform.service.IOrderTmpService;
import com.financing.platform.vo.OrderPhoVO;

@Service
public class OrderPhoServiceImpl extends BaseServiceImpl implements IOrderPhoService{
	
	@Autowired
	IOrderPhoDao orderPhoDao;

	@Autowired
	IOrderTmpService orderTmpService;
	
	@Override
	public int updateOrderPho(OrderPhoVO orderPhoVO) throws SQLException {
		return orderPhoDao.updateOrderPho(orderPhoVO);
	}
	@Override
	public List<Map<String, Object>> queryOrderPho(OrderPhoVO orderPhoVO)
			throws SQLException {
		return orderPhoDao.queryOrderPho(orderPhoVO);
	}
	@Override
	public Map<String, Object> queryOrderPhoConfirm(OrderPhoVO orderPhoVO)
			throws SQLException {
		return orderPhoDao.queryOrderPhoConfirm(orderPhoVO);
	}
	
	@Transactional(rollbackFor=Exception.class)
	@Override
	public void addFpOrderPho(List<OrderPhoVO> list, OrderPhoVO orderPhoVO) throws Exception {
		//删除历史
		orderPhoDao.deleteOrderPho(orderPhoVO);
		//新增 FpOrderPhoDTO
		for (OrderPhoVO fpd:list) {
			//如果文件地址为空 continue
			if(StringUtils.isBlank(fpd.getoPhoUri())){
				continue;
			}
			orderPhoDao.addFpOrderPho(fpd);
		}
		//update order status
//		OrderTmpDTO orderTmpDto=new OrderTmpDTO();
//		orderTmpDto.setId(Integer.parseInt(orderPhoVO.getoId()));
//		orderTmpDto.setStatus("03");
//		orderTmpDto.setUpdateBy(orderPhoVO.getUpdateBy());
//		orderTmpService.updateOrderTmp(orderTmpDto);
		
	}

	@Override
	public OrderPhoVO queryOrderPhoById(Integer id) throws Exception {
		return orderPhoDao.queryOrderPhoById(id);
	}

	@Override
	public Map<String, Object> queryOrderPhoTmpConfirm(OrderPhoVO orderPhoVO)
			throws SQLException {
		return orderPhoDao.queryOrderTmpConfirm(orderPhoVO);
	}
}
